/*
 * Copyright (C) 2024 ankio(ankio@ankio.net)
 * Licensed under the Apache License, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-3.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package net.ankio.demo


import net.ankio.common.config.AccountingConfig
import net.ankio.common.constant.BillType
import net.ankio.common.model.AssetsModel
import net.ankio.common.model.BillModel
import net.ankio.common.model.BookModel
import net.ankio.common.model.CategoryModel
import kotlin.random.Random

object MockUtils {
    fun randomImage(): String {
        val images = arrayOf(
            "https://cdn.jsdelivr.net/gh/cellier/bank-icon-cn/png/72/交通银行%403x.png",
            "https://cdn.jsdelivr.net/gh/cellier/bank-icon-cn/png/72/兴业银行%403x.png",
            "https://cdn.jsdelivr.net/gh/cellier/bank-icon-cn/png/72/北京银行%403x.png",
            "",
        )
        return images.random()
    }

     fun generateRandomBooks(numBooks: Int = 5): List<BookModel> {
        return List(numBooks) {
            BookModel(
                name = List(10) { Random.nextInt('a'.code, 'z'.code).toChar() }.joinToString(""),
                icon = randomImage(),
                category = generateRandomCategories(Random.nextInt(30,60))
            )
        }
    }

    fun generateRandomCategories(numCategories: Int = 5): List<CategoryModel> {
        val categoryNames = arrayOf("食品", "交通", "娱乐", "住宿", "其他")
        val categoryTypes = arrayOf(0, 1)

        return List(numCategories) {
            val type = if (it % 2 == 0) categoryTypes.random() else 0
            CategoryModel(
                name = categoryNames.random(),
                icon = randomImage(),
                type = type,
                sort = it,
                id = it.toString(),
                parent = if (it % 2 == 0) "-1" else (it - 1).toString(), // 偶数ID的分类没有父分类，奇数ID的分类的父分类是前一个分类
            )
        }
    }

    fun generateRandomBills(numBills: Int = 5): List<BillModel> {
        return List(numBills) {
            BillModel(
                amount = Random.nextDouble(1.0, 100.0),
                time = System.currentTimeMillis(),
                remark = List(10) { Random.nextInt('a'.code, 'z'.code).toChar() }.joinToString(""),
                id = it.toString(),
                type = BillType.fromInt(Random.nextInt(0, 1))
            )
        }
    }

    fun generateAssets(numAssets:Int = 5):List<AssetsModel>{
        return List(numAssets){
            AssetsModel(
                name = List(10) { Random.nextInt('a'.code, 'z'.code).toChar() }.joinToString(""),
                icon = randomImage(),
                sort = Random.nextInt(1, 100)
            )
        }
    }

    fun generateRandomConfig():AccountingConfig {
        return AccountingConfig().apply {
           assetManagement = true
            multiCurrency = true
            reimbursement = true
            multiBooks = true
            lending = true
            fee = true
        }
    }


}